home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / bison / CallingCon < prev    next >
Text File  |  1995-06-28  |  1KB  |  43 lines

  1. Calling Convention
  2. Previous: <Lexical=>Lexical> * Next: <Token Values=>TokenValue> * Up: <Lexical=>Lexical>
  3.  
  4. #Wrap on
  5. {fH4}Calling Convention for {fCode}yylex{f}{f}
  6.  
  7. The value that {fCode}yylex{f} returns must be the numeric code for the type
  8. of token it has just found, or 0 for end-of-input.
  9.  
  10. When a token is referred to in the grammar rules by a name, that name
  11. in the parser file becomes a C macro whose definition is the proper
  12. numeric code for that token type.  So {fCode}yylex{f} can use the name
  13. to indicate that type.  \*Note <Symbols=>Symbols>.
  14.  
  15. When a token is referred to in the grammar rules by a character literal,
  16. the numeric code for that character is also the code for the token type.
  17. So {fCode}yylex{f} can simply return that character code.  The null character
  18. must not be used this way, because its code is zero and that is what
  19. signifies end-of-input.
  20.  
  21. Here is an example showing these things:
  22.  
  23. #Wrap off
  24. #fCode
  25. yylex ()
  26. \{
  27.   …
  28.   if (c == EOF)     \/\* Detect end of file. \*\/
  29.     return 0;
  30.   …
  31.   if (c == '+' || c == '-')
  32.     return c;      \/\* Assume token type for `+' is '+'. \*\/
  33.   …
  34.   return INT;      \/\* Return the type of the token. \*\/
  35.   …
  36. \}
  37. #f
  38. #Wrap on
  39.  
  40. This interface has been designed so that the output from the {fCode}lex{f}
  41. utility can be used without change as the definition of {fCode}yylex{f}.
  42.  
  43.